package mr;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashMap;

public class Test4Reduce {

    public static void main(String[] args) throws Exception {

        File file = new File("F:\\数加\\代码\\nanshan\\part");
        File[] files = file.listFiles();

        HashMap<String, Integer> map = new HashMap<>();

        assert files != null;
        for (File f : files) {

            BufferedReader br = new BufferedReader(new FileReader(f));
            String line;
            while ((line= br.readLine())!=null){

                String clazz = line.split(":")[0];
                Integer sum = Integer.valueOf(line.split(":")[1]);

                if (!map.containsKey(clazz)){
                    map.put(clazz,sum);
                }else {
                    map.put(clazz,map.get(clazz)+sum);
                }

            }

            br.close();
        }

        System.out.println(map);

    }

}
